<?php

namespace Home\Model;
use Think\Model;
/**
 * Admin后台管理员
 * @author  qinshan
 * @since   1.0
 */
class Admin
{
    /**
     * 执行登录
     * @param $username
     * @param $password
     * @return bool
     */
    public static function login($username, $password)
    {
        //var_dump($_POST);exit;
        $data['username']=I("post.username");
        $data['password_hash']=I("post.password");
        $res=M('user')->where($data)->find();
        //var_dump($res);exit;
        if ($res) {

            session('home.id', $res['id']);
            session('home.username', $res['username']);
            session('home.name', $res['name']);

            return true;
        }
        return false;
    }

    /**
     * 返回admin是否已登录
     * @return zhi
     */
    public static function isLogin()
    {
        return session('home.id');
    }

    /**
     * 当前登录用户信息
     * @return array|null
     */
    public static function user()
    {
        if (!self::isLogin()) {
            return null;
        }
        return array(
            'id' => session('home.id'),
            'username' => session('home.username'),
            'name' => session('home.name'),
        );
    }

}